<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>

        <ui:composition template="/admin/adminTemplate.xhtml">

            <ui:define name="title">
                Admin Schema
            </ui:define>

            <ui:define name="page">
                <h:outputStylesheet library="css" name="schemaStyle.css"  />
                <div class="left">
                    Aktuell vecka: <h:outputText value="#{schemaBean.weekToday}"/><br/>
                    Dagens datum: <h:outputText value="#{schemaBean.dateToday}"/>
                </div>
                <table class="schema">
                    <tr>
                        <td class="right">
                            <h:form>
                                <h:commandButton value="&lt;&lt;" action="#{schemaBean.prevWeek()}" />
                            </h:form>
                        </td>
                        <td class="center">
                            <h:outputText value="#{schemaBean.week}" />   
                        </td>
                        <td class="left">
                            <h:form>
                                <h:commandButton value="&gt;&gt;" action="#{schemaBean.nextWeek()}" />
                            </h:form>
                        </td>
                    </tr>
                    <tr>
                        <td class="center" colspan="3">
                            <table>
                                <tr>
                                    <td></td>                         
                                    <ui:repeat value="#{schemaBean.weekDates}" var="date">
                                        <td>
                                            <h:outputText value="#{date}" />
                                        </td>
                                    </ui:repeat>     
                                </tr>
                                #{shiftBean.firstSetShifts()}
                                #{shiftBean.update(insertBean.updated)}
                                #{empBean.firstSetEmps()}
                                #{empBean.update(insertBean.updated)}
                                #{insertBean.setEmp_unames(schemaBean.getShiftEmpsUsername(shiftBean.shifts, insertBean.shift_date, insertBean.shift_time))}
                                #{insertBean.setUpdated(false)}
                                #{insertBean.setAll_emps(empBean.emps)}
                                <ui:repeat value="#{schemaBean.shift}" var="shift">
                                    <tr>
                                        <td><h:outputText value="#{shift}" /></td>
                                        <ui:repeat value="#{schemaBean.weekDates}" var="date">
                                            <td class="#{schemaBean.isSet(shiftBean.shifts, date, shift)}">
                                                <h:form>
                                                    <h:commandLink styleClass="shift" action="#{insertBean.setShift(schemaBean.getShiftID(shiftBean.shifts, date, shift), date, shift, schemaBean.getShiftEmpsUsername(shiftBean.shifts, date, shift))}">
                                                        <h:outputText escape="false" value="#{schemaBean.getShiftEmps(shiftBean.shifts, date, shift)}" />
                                                    </h:commandLink>
                                                </h:form>
                                            </td>
                                        </ui:repeat>
                                    </tr>
                                </ui:repeat>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td class="center" colspan="3">
                            <br/>
                            <h:panelGroup layout="block" rendered="#{insertBean.shift_ID != 0}">
                                <h:outputText value="#{insertBean.shift_date}" />
                                [
                                <h:outputText value="#{insertBean.shift_time}" />
                                ]
                                <ui:repeat value="#{insertBean.emp_unames}" var="se">
                                    <h:form prependId="false">
                                        <h:outputText value="#{insertBean.getEmpName(se)}" />
                                        <h:commandButton value="Ta Bort" action="#{insertBean.deleteEmp(se)}"/>
                                    </h:form>
                                </ui:repeat>
                                <h:form prependId="false">
                                    <h:selectOneMenu value="#{insertBean.new_emp}">
                                        <f:selectItems value="#{insertBean.all_emps}" var="c" itemLabel="#{c.emp_name}" itemValue="#{c.username}" />
                                    </h:selectOneMenu>
                                    <h:commandButton value="Lägg Till" action="#{insertBean.insertEmp()}" />
                                </h:form>
                            </h:panelGroup>
                        </td>
                    </tr>
                </table>
            </ui:define>

        </ui:composition>

    </body>
</html>
